package com.changcheng.service.Imp;

import com.changcheng.mapper.PictureMapper;
import com.changcheng.pojo.Picture;
import com.changcheng.service.FileService;
import com.changcheng.service.PictureService;
import com.changcheng.utils.PageUtil;
import com.changcheng.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class PictureServiceImp implements PictureService {


    @Autowired
    private FileService fileService;
    @Autowired
    private FileServiceImp fileServiceImp;
    @Autowired
    private PictureMapper pictureMapper;

    @Override
    public void add(Picture picture) {


        picture.setCreat_time(LocalDate.now());
//        picture1.setContent("");
//        picture.setPicture((String)session.getAttribute("url"));
        pictureMapper.add(picture);




    }

    @Override
    public R delete(Integer id) {
         pictureMapper.delete(id);
        return R.ok();
    }

    @Override
    public R update(Picture picture) {
        pictureMapper.update(picture);
        return R.ok();

        }

    @Override
    public List<Picture> select(Integer pageNum,Integer pageSize) {
      List<Picture> select =  pictureMapper.select();
//      分页处理
      List<Picture> select1 = PageUtil.startPage(select,pageNum,pageSize);
      return select1;

    }

    @Override
    public List<Picture> findIdPicture(Integer id) {
        List<Picture> findIdPicture = pictureMapper.findIdPicture(id);

        return findIdPicture;
    }


}
